<?php
namespace app\admin\controller;

use app\common\model\HeartRead as HeartReadModel;
/**
 * 一心专念控制器
 * Class Idea
 * @package app\index\controller
 */
class Heartread extends Base
{
    /**
     * [index  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function index()
    {
        $data = input('param.');
        $this->getPageAndSize($data);
        $model = new HeartReadModel();
        $map = [];
        $map1 = [];
        $map2 = [];
        $map3 = [];
        $map4 = [];
        $user = $this->user;
        try{
            $today_start = strtotime(date('Y-m-d',time()));
            $today_end = $today_start + 24*60*60;
            $map1['h.starttime'] = ['between',[$today_start,$today_end]];
            $todaycount = $model->getCount($map1);//满足条件的总数
            $map3['starttime'] = ['between',[$today_start,$today_end]];
            $today_person = $model->getPerson($map3);

            $yestoday_start = $today_start - 24*60*60;
            $map2['h.starttime'] = ['between',[$yestoday_start,$today_start]];
            $yestodaycount = $model->getCount($map2);
            $map4['starttime'] = ['between',[$yestoday_start,$today_start]];
            $yestoday_person = $model->getPerson($map4);

            $all_person = $model->getPerson([]);
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size);
            foreach($lists as &$v){
                $http = substr($v['img'],0,4);
                if($http != 'http'){
                    if(empty($v['img'])){
                        $v['img'] = 'https://fushan.oss-cn-hangzhou.aliyuncs.com/nouser.png';
                    }else{
                        $v['img'] = config('domain_name').$v['img'];
                    }
                }
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看一心专念记录',1,$user);
        return admin_json(1,'获取成功',[
            'today_person' => count($today_person),
            'today_count' => $todaycount,
            'yestoday_person' => count($yestoday_person),
            'yestoday_count' => $yestodaycount,
            'all_person' => count($all_person),
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}